package cn.opencodes.framework.core.base;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.opencodes.framework.core.utils.WebUtils;
import cn.opencodes.framework.core.vo.UserRoot;
import cn.opencodes.framework.tools.vo.CoreConst;
import cn.opencodes.framework.tools.vo.Query;

/**
 * Controller公共组件
 * @author HJ
 */
public abstract class BaseController {
	
	public Query query(Object ...objs){
		Query query = new Query(objs);
		return query;
	}
	
	public Query query(HttpServletRequest req){
		Map<String, Object> params = WebUtils.extractToMap(req);
		Query query = new Query(params);
		return query;
	}
	
	public Query query(Map<String, Object> params){
		Query query = new Query(params);
		return query;
	}
	
	public UserRoot getUserRoot(){
		return WebUtils.getUser();
	}
	
	public String getUserName(){
		return getUserRoot().getUsername();
	}
	
	public long getUserId(){
		return getUserRoot().getId();
	}
	
	public boolean isSuperAdmin(){
		return 
			getUserId() == CoreConst.SUPER_ADMIN ;
	}
	
	
	
}
